package com.sk.weichat.ui.mucfile.bean;

import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.IntDef;

import java.io.File;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

public class FileBean implements Parcelable {
    public static final int FILE = 0;
    public static final int DIR = 1;
    public static final int IMAGE = 2;
    public static final int PDF = 3;
    public static final int DOC = 4;
    public static final int EXCEL = 5;
    public static final int PPT = 6;
    public static final int MP4 = 7;
    public static final int AVI = 8;
    public static final int MP3 = 9;
    public static final int ZIP = 10;
    public static final int TXT = 11;
    public static final int APK = 12;

    public FileBean() {
    }

    @Retention(RetentionPolicy.SOURCE)
    @Target({ElementType.PARAMETER})
    @IntDef({FILE, DIR, IMAGE, PDF, DOC, EXCEL, PPT, MP4, AVI, MP3, ZIP, TXT, APK})
    public @interface Type {
    }

    public static final String FileBean_Key = "FileBean_Key";

    private int type;
    private boolean isChecked;
    private File file;
    private String fileName = "";
    private boolean isExpand = false;

    //文件的分类名称，如：视频、pdf、压缩文件、电子书等
    private String typeName = "";

    protected FileBean(Parcel in) {
        type = in.readInt();
        isChecked = in.readByte() != 0;
        fileName = in.readString();
        isExpand = in.readByte() != 0;
        typeName = in.readString();
        file = (File) in.readSerializable();
    }

    public static final Creator<FileBean> CREATOR = new Creator<FileBean>() {
        @Override
        public FileBean createFromParcel(Parcel in) {
            return new FileBean(in);
        }

        @Override
        public FileBean[] newArray(int size) {
            return new FileBean[size];
        }
    };

    public boolean isChecked() {
        return isChecked;
    }

    public void setChecked(boolean checked) {
        isChecked = checked;
    }

    public File getFile() {
        return file;
    }

    public void setFile(File file) {
        this.file = file;
    }

    public String getFileName() {
        return fileName;
    }

    public void setFileName(String fileName) {
        this.fileName = fileName;
    }

    public boolean isExpand() {
        return isExpand;
    }

    public void setExpand(boolean expand) {
        isExpand = expand;
    }

    public String getTypeName() {
        return typeName;
    }

    public void setTypeName(String typeName) {
        this.typeName = typeName;
    }

    public int getType() {
        return type;
    }

    public void setType(@Type int type) {
        this.type = type;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(type);
        dest.writeByte((byte) (isChecked ? 1 : 0));
        dest.writeString(fileName);
        dest.writeByte((byte) (isExpand ? 1 : 0));
        dest.writeString(typeName);
        dest.writeSerializable(file);
    }
}
